import { ActiveBaseIcon } from "../activity/icon/ActiveBaseIcon";
import { EBattlefieldPlayerState } from "../../model/defin/EBattlefieldPlayerState";
import { LayerManager } from "../../manager/LayerManager";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ViewEvent } from "../../../mvc/events/ViewEvent";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
//class NewBattlefieldIconView
    
    export  class NewBattlefieldIconView extends ActiveBaseIcon
    {
        constructor()
        {
            super();
            this.currentState = EBattlefieldPlayerState.EBattlefieldStatusClose;
            this.layer = LayerManager.rightTopUILayer;
            this.createChildren();
            this.addListeners();
            return;
        }

        /* internal  */createChildren(): void
        {
            this._spEnterBtnContainer = new Object /* flash.display.Sprite */();
            this._spEnterBtnContainer.mouseEnabled = false;
            this.addChild(this._spEnterBtnContainer);
            this._btnShowBFTips = ObjCreate.createGLoadedButton(ResFileConst.NewBattlefield, 0, 0, 50, 50, this._spEnterBtnContainer);
            var loc1=new GTextFormat(FontUtil.songtiName, 12, 16711680);
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._tfEnterLimit = ObjCreate.createTextField("", 0, 47, 48, 20, null, loc1);
            this._tfEnterLimit.mouseEnabled = false;
            return;
        }

        /* internal  */addListeners(): void
        {
            this._btnShowBFTips.addEventListener(flash.events.MouseEvent.CLICK, this.onClickShowBFTips);
            this.addEventListener(ViewEvent.Hide, this.onHide);
            return;
        }

        /* internal  */onHide(arg1: ViewEvent): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.NewBattlefieldShowOrHideEntrance, false));
            return;
        }

        /* internal  */onClickShowBFTips(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.NewBattlefieldAutoShowOrHideEntrance));
            return;
        }

        public showLightMask(): void
        {
            if (!this._lightMask) 
            {
                this._lightMask = ObjectPool.getObject(LightMask);
                this._lightMask.transform.matrix = new Object /* flash.geom.Matrix */();
                this._lightMask.x = 2;
                this._lightMask.y = 2;
                this._lightMask.scaleX = 55 / 42.5;
                this._lightMask.scaleY = 55 / 42.5;
                this._btnShowBFTips.addChild(this._lightMask);
            }
            return;
        }

        public hideLightMask(): void
        {
            if (this._lightMask) 
            {
                if (this._lightMask.parent) 
                {
                    this._lightMask.parent.removeChild(this._lightMask);
                }
                this._lightMask.x = 0;
                this._lightMask.y = 0;
                this._lightMask.width = 40;
                this._lightMask.height = 40;
                ObjectPool.disposeObject(this._lightMask);
                this._lightMask = null;
            }
            return;
        }

        public startCountdownLimitEnter(arg1: Date): void
        {
            return;
        }

        public set state(arg1: EBattlefieldPlayerState)
        {
            this.currentState = arg1;
            return;
        }

        /* internal  */onLimitEnterTimeChange(arg1: SecTimer): void
        {
            var loc1=arg1.repeatCount;
            if (loc1 == 0 && this._tfEnterLimit.parent) 
            {
                this._tfEnterLimit.parent.removeChild(this._tfEnterLimit);
                if (this.currentState == EBattlefieldPlayerState.EBattlefieldStatusWait) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.NewBattlefieldShowOrHideEntrance, true));
                    this.showLightMask();
                }
            }
            var loc2=Math.floor(loc1 / 60);
            var loc3=loc1 % 60;
            var loc4=(loc4 = (loc4 = "") + ((loc2 < 10 ? "0" : "") + loc2 + ":")) + ((loc3 < 10 ? "0" : "") + loc3);
            this._tfEnterLimit.text = loc4;
            return;
        }

        public stopLimitEnterCountDown(): void
        {
            return;
        }

        /* internal */ /* var */_spEnterBtnContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_btnShowBFTips: GLoadedButton;

        /* internal */ /* var */_tfEnterLimit: Object /* flash.text.TextField */;

        /* internal */ /* var */_lightMask: LightMask;

        /* internal */ /* var */_secLimitEnterTimer: SecTimer;

        /* internal */ /* var */currentState: EBattlefieldPlayerState;
    }
